<template>
	<div class="layout-padding cache">
		<el-card class="!border-none" shadow="never">
			<div>
				<div class="mb-4 lg">状态信息</div>

				<div class="el-table--enable-row-transition el-table--large el-table">
					<el-scrollbar>
						<table class="el-table__body" cellspacing="0">
							<tbody>
								<tr class="el-table__row">
									<td class="el-table__cell">
										<div class="cell">设备ID</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.deviceName }}</div>
									</td>
								</tr>
								<tr class="el-table__row">
									<td class="el-table__cell">
										<div class="cell">电梯门</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ getDoorStatusText(statusInfo.doorStatus) }}</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">运行状态</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">
											{{ getRunningStatusText(statusInfo.runningStatus) }}
										</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">楼层编号</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.floorNumber }}</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">楼层名称</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.floorName }}</div>
									</td>
								</tr>
								<tr class="el-table__row">
									<td class="el-table__cell">
										<div class="cell">速度</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.speed / 100 }} m/s</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">气压</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">
											{{ statusInfo.press }} Pa
										</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">电瓶车</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.motoStatus == 1 ? '有' : '无' }}</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">人数</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.personCount }}</div>
									</td>
								</tr>
								<tr class="el-table__row">
									<td class="el-table__cell">
										<div class="cell">累计运行次数</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.runningCount }}</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">累计开门次数</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">
											{{ statusInfo.runningOpenCount }}
										</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">累计里程</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.runningMile }}</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">累计运行时间</div>
									</td>
									<td class="el-table__cell">
										<div class="cell">{{ statusInfo.runningTime }}</div>
									</td>
								</tr>
							</tbody>
						</table>
					</el-scrollbar>
				</div>
			</div>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="status">
import { getStatus } from '/@/api/evaboxcloud/deviceMonitor';
import {useDict} from "/@/hooks/dict";

const deviceName = ref();

const route = useRoute();

// 定义查询字典
const { evabox_door_status,evabox_running_status } = useDict('evabox_door_status','evabox_running_status')

const statusInfo = ref<any>({});

const getStatusInfo = async (deviceName:string) => {
	const res = await getStatus(deviceName);
	statusInfo.value = res.data;
};

const getDoorStatusText = (doorStatus: number) => {
	if (doorStatus == 0) {
		return '关闭';
	} else if (doorStatus == 1) {
		return '打开';
	} else {
		return '未知';
	}
};

const getRunningStatusText = (runningStatus: number) => {
	if (runningStatus == 0) {
		return '上行';
	} else if (runningStatus == 1) {
		return '下行';
	} else {
		return '静止';
	}
};

const timer = setInterval(() => {
	getStatusInfo(deviceName.value);
}, 2000);

onMounted(() => {
	deviceName.value = route.query.deviceName;
	getStatusInfo(deviceName.value);
});

// 页面卸载时
onUnmounted(() => {
	clearInterval(timer);
});


</script>

<style scoped>
.el-table .el-table__cell {
	min-width: 120px;
}
</style>
